package com.lzy.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.common.result.R;
import com.lzy.srb.core.pojo.entity.Borrower;
import com.lzy.srb.core.pojo.vo.BorrowerApprovalVO;
import com.lzy.srb.core.pojo.vo.BorrowerDetailVO;
import com.lzy.srb.core.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
public class AdminBorrowerController {

    @Autowired
    BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(@PathVariable("page") Long page,
                      @PathVariable("limit") Long limit,
                      @RequestParam String keyword){

        Page<Borrower> pageParam = new Page<>(page,limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam,keyword);
        return R.ok().data("pageModel",pageModel);

    }


    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id){
        BorrowerDetailVO bdv = borrowerService.getBorrowerDetailVOById(id);
        return R.ok().data("borrowerDetailVO",bdv);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }


}
